package models

type InOrderDetail struct {
	Model
	InOrderId   int     `json:"in_order_id"`
	Price       float64 `json:"price"`
	Num         int     `json:"num"`
	ProductId   int     `json:"product_id"`
	ProductName string  `json:"product_name"`
	ProductSpec string  `json:"product_spec"`
}

func AddInOrderDetail(data map[string]interface{}, mainId int) bool {
	db.Create(&InOrderDetail{
		InOrderId:   mainId,
		Price:       data["price"].(float64),
		Num:         data["num"].(int),
		ProductId:   data["product_id"].(int),
		ProductName: data["product_name"].(string),
		ProductSpec: data["product_spec"].(string),
	})
	return true
}

func EditInOrderDetail(data InOrderDetail) bool {
	err := db.Model(&InOrderDetail{}).Where("id=?", data.ID).Update(&InOrderDetail{
		Price: data.Price,
		Num:   data.Num,
	}).Error
	if err != nil {
		return false
	}
	return true
}
